Home |
| Latest | About | Random
# Text editor and terminal. The "official PIC 10A way" is with an IDE like XCode and VS. **So stop here before you you read on. Be warned, you may brick your computer if you do crazy things, oh no! On the other hand, that's a way to learn...** I will probably get yelled at but... If you want to be a *rebel* and if you just want to use a simple editor (that has syntax highlighting + quick terminal access), I recommend - Zed editor [https://zed.dev/](https://zed.dev/) It is *free and open source software* (FOSS), as far as I know, until it is not. Make sure to turn off telemetry for most privacy. - I don't work for them and in fact I just recently learned about it. However from what I have seen, it is clean and simple enough to not be too confusing to use. - VS Code - Notepad++ (Windows only) - many... - In fact, you should write your own text editor, and not trust anything else. Once you save a file as `.cpp`, in Zed, for example you can hit `ctrl` + backtick (same key as the squiggle ~) to toggle open the terminal at where the file is, and in that terminal you can type ```cmd c++ filename.cpp -o output.exe && ./output.exe ``` to **both build an executable and run the executable**. Here `filename.cpp` is the name of your file, and `output.exe` is the name of the executable it will build. - Note, provided that you have installed XCode or VS with the C++ toolchain, the command `c++` should work. You can check by typing `c++ -v`. - Above only works if your terminal is at the location of where the file is. Otherwise you will have to **change directories** using commands like `cd`. - `cd ..` to go up a folder - `cd FolderName` to go into the folder `FolderName`, provided it is a subfolder of where you are. - If you are interested in learning more of this power, talk to me in office hours. You can choose your own source file name `filename.cpp` and the binary executable name `output.exe`. Now to explain `c++ filename.cpp -o output.exe && ./output.exe`, which does two things: - The command `c++ filename.cpp` builds (compiles and links) our C++ source code file called `filename.cpp`. The flag `-o` designates the name of the output binary, in this case `output.exe`. - If you omit the flag `-o` and the output name, then the default binary name is sometimes `a` or `a.exe` or `a.o`. Look in your folder/finder to check. - The command `&&` is standard Unix (and on windows PowerShell as well as Command Prompt) for, "if the previous command is successful, then do the following". - And `./output.exe` executes the binary. So this single command does both building the executable and running said executable. An annoyance is that if you use Windows Command Prompt instead, you have to type `.\output.exe` instead. In fact, you can do those two steps separately, do ```cmd c++ filename.cpp -o output.exe ``` to build an executable called `output.exe` from `filename.cpp`, and ``` ./output.exe ``` to run it. Again, if you use Windows Command Prompt, then you need to use `.\output.exe` instead to run the executable. At any point if you want to panic and stop the terminal from doing what it is doing, you can hit `ctrl` + `c` to send a interrupt signal and stop everything. In fact, any text editor would work, they just have different features baked in. You'll still need to run that command in the terminal. Some useful commands, on Unix / MacOS / Windows PowerShell, you can type ```cmd clear ``` to clear the terminal. If it is Windows Command Prompt, then `cls` clears the screen. And you can often use the arrow key like `↑` to `↓` to navigate command history in your terminal. And the `tab` key often give autocomplete suggestions of partial inputs.